<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/admin/lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/admin/css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <button class="layui-btn layui-btn-sm layui-btn-danger data-delete-btn" lay-event="batchDelete"> 多选删除 </button>
            </div>
        </script>

        <table class="layui-hide" id="loginLogTableId" lay-filter="employeeTableFilter"></table>

        <script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="edit">编辑</a>
            <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">删除</a>
        </script>

    </div>
</div>
<script src="/static/admin/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form', 'table','jquery'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table;

        table.render({
            id:'loginLogId',
            elem: '#loginLogTableId',
            url: '/admin/log/queryLoginLog',
            toolbar: '#toolbarDemo',
            defaultToolbar: [],
            cols: [
                [
                {type: "checkbox", width: 50},
                {field: 'loginLogId', title: '日志序号'},
                {field: 'loginName', title: '登录名'},
                {title: '登录类型',templet:function (res) {

                    if (res.loginType == 0){
                        return "客户";
                    }else if(res.loginType == 1){
                        return "运输";
                    }else if(res.loginType == 2){
                        return "员工";
                    }

                    }},
                {field: 'loginIp', title: '登录IP地址'},
                {field: 'loginSystem', title: '登录系统'},
                {field: 'createTime', title: '登录时间'}
                //{title: '操作', minWidth: 150, toolbar: '#currentTableBar', align: "center"}
            ]
            ],
            page: true
        });

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            var result = JSON.stringify(data.field);
            layer.alert(result, {
                title: '最终的搜索信息'
            });

            //执行搜索重载
            table.reload('loginLogTableId', {
                page: {
                    curr: 1
                }
                , where: {
                    searchParams: result
                }
            }, 'data');

            return false;
        });

        /**
         * toolbar监听事件
         */
        table.on('toolbar(employeeTableFilter)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            if (obj.event === 'batchDelete') {  // 监听批量删除操作

                var data = checkStatus.data;

                if (data.length < 1){
                    layer.msg("最少选中一条数据")
                    return false;
                }

                layer.confirm('确认要批量删除登录日志吗？', {
                    btn : [ '确定', '取消' ]//按钮
                }, function(index) {

                    var arrListId = [];
                    $.each(data,function (index,item) {

                        arrListId.push(item.loginLogId);

                    })


                    $.ajax({
                        url:'/admin/log/batchDeleteLoginLog',
                        type:'post',
                        data:{
                            logIdList:arrListId.join("-")
                        },
                        dataType:'json',
                        success:function (res) {

                            layer.msg(res.message+",正在刷新表格",function () {

                                //刷新表格
                                table.reload('loginLogId', {
                                    url:'/admin/log/queryLoginLog'

                                });

                            })

                        }
                    })

                    layer.close(index);

                });



            }
        });

        //监听表格复选框选择
        table.on('checkbox(employeeTableFilter)', function (obj) {

        });

        table.on('tool(employeeTableFilter)', function (obj) {
            var data = obj.data;

            console.log(data)

            if (obj.event === 'edit') {

                var index = layer.open({
                    title: '编辑用户',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: '../page/table/edit.html',
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
                return false;
            } else if (obj.event === 'delete') {
                layer.confirm('真的删除行么', function (index) {
                    obj.del();
                    layer.close(index);
                });
            }
        });

    });
</script>

</body>
</html>
